<template>
	<view class="content" :style="{height: tabHeightVal}">
		<view class="topcomtent">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
				<view class="content_Gaik">
					<view class="content_head">
						<view style="float: left;width: 120rpx;height: 120rpx;line-height: 120rpx;background-color: #edf1f4;
								 color: #6D8AF9;text-align: center;border-radius:60rpx;font-size: 30rpx;">
							{{CurrentUserName}}
						</view>
						<view style="float: left;font-size: 30rpx;margin-left: 50rpx;color: #FFFFFF;margin-top: -15rpx;">{{CurrentUserName}}</view>
					</view>
					<view style="height: 400rpx;">
						<view style="height: 50rpx;width: 85%;float: left;margin-top: 0rpx;font-size: 30rpx;border-bottom: 1px #FFFFFF solid;margin-left: 50rpx;
						padding-bottom: 20rpx;padding-top: 20rpx;">
							<view style="line-height: 50rpx;height: 50rpx;width: 100%;float: left;text-align:left;color: #FFFFFF;">{{CurrentDepartmentName}}</view>
						</view>						
					</view>
				</view>
				<view style="background-color: #FFFFFF;height: 90rpx;line-height: 90rpx;margin-top: -55rpx;text-align: center;font-size: 30rpx;" @click.stop="confirmMoreBtns(3)">
					退出登录
				</view>
			</mescroll-body>

		</view>
		<aui-dialog
			ref="dialog"
			:title="auiDialog.title"
			:msg="auiDialog.msg"
			:btns="auiDialog.btns"
			:mask="auiDialog.mask"
			:maskTapClose="auiDialog.maskTapClose"
			:items="auiDialog.items"
			:theme="auiDialog.theme"
			@callback="dialogCallback"
		></aui-dialog>
		<tab-bar class="fixs" ref='commentTabbat' :actives='active'></tab-bar>
	</view>
</template>

<script>
	import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	import {aui} from '@/common/aui/js/aui.js';	
	import auiDialog from '@/components/aui-dialog/aui-dialog.vue';
	import tabBar from '@/components/tabbar/tabbar3.vue'
	import {
		openComDB,
		executeSQL,
		dropSQL
	} from "@/pages/API/sqllite/sqllite.js";
	var self;
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			MescrollBody,
			MescrollUni,
			auiDialog,
			tabBar
		},
		data() {
			return {
				downOption: {
					auto: false,
					native: false,
					beforeEndDownScroll: 1000,
					textInOffset: "下拉刷新",
					textOutOffset: "释放刷新",
					textLoading: "加载中..."
				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					auto: false, // 不自动加载
					page: {
						size: 6 // 每页数据的数量,默认10
					},
					noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					},
					toTop: {
						src: "../../static/images/icon-up.png",
						offset: 50,
						duration: 300,
						zIndex: 9990,
						right: 20,
						bottom: 120,
						safearea: false,
						width: 72,
						radius: "50%",
						left: null
					},
				},
				loginName: "",
				CurrentUserName:"",
				CurrentUserRoleName:"",
				CurrentDepartmentName:"",
				model: {},
				contentHeight: null,
				auiDialog: {
					title: '',
					msg: '',
					btns: [{name: '确定'}],
					mask: true,
					maskTapClose: true,
					items: [],
					theme: 1,
				},
				active: Number || 4,
			}
		},
		computed: {
			tabHeightVal() {
				return (uni.getSystemInfoSync().windowHeight) + 'px'
			}
		},
		onBackPress(options) {
			uni.setStorageSync('setStatusIndexFunc', 0);
			//uni.navigateTo({
			//	url: '../home/Index',
			//	animationType:'slide-in-left',
			//	    animationDuration: 400
			//});
			return false;
		}, 
		onLoad(){
			//底部导航开始
			let temp = uni.getStorageSync('setStatusIndexFunc') || 0
			uni.setStorageSync('setStatusIndexFunc', temp)
			this.active = temp
			this.$nextTick(()=>{
				this.$refs.commentTabbat.getSetting(temp)
				this._initData();
			})
			
			self=this;
			self.CurrentUserName="";
			self.CurrentUserRoleName="";
			self.CurrentDepartmentName="";
			
			
			uni.getStorage({
				key:"userInfo",
				success:function(res){
					console.log(JSON.parse(res.data).userName);
					self.CurrentUserName=JSON.parse(res.data).userName;
				}
			})
			
			uni.getStorage({
				key:"userRoles",
				success:function(res){
					console.log(res);
					let rolename="";
					for(var i=0;i<res.data.length;i++){
						if(i!=(res.data.length-1)){
							rolename=rolename+res.data[i].roleName+";"
						}else{
							rolename=rolename+res.data[i].roleName
						}
						
					}
					self.CurrentUserRoleName=rolename;
				}
			})
			
			uni.getStorage({
				key:"userDept",
				success:function(res){
					console.log(res);
					let departname=res.data.orgName;
					
					self.CurrentDepartmentName=departname;
				}
			})
			
			//let userRoles= uni.getStorageInfoSync("userRoles");
			//console.log(userRoles);
			
			
			let userDept= uni.getStorageInfoSync("userDept");
			console.log(userDept);
			
			
			//底部导航结束
		},
		provide(){
			return {
				_mainFuncInit: this._mainFuncInit
			}
		},
		onShow(){
			
			
			
		},
		methods: {
			/**
			 * @name 公共点击函数
			 * */
			_mainFuncInit(){
				this.active = uni.getStorageSync('setStatusIndexFunc') || 0
				console.log(this.active)
				if(this.active==1){
					uni.navigateTo({
						url: '../asset/myasset',
					});	
				}else if(this.active==3){
					uni.navigateTo({
						url: '../home/home',
					});	
				}else if(this.active==0){
					uni.navigateTo({
						url: '../home/Index',
					});	
				}
			},
			/**
			 * @name 首页数据初始化 
			 * */
			_initData(){
				this._mainFuncInit();
			},
			sysOut:function(){
				self=this;
				uni.showModal({
					title: '固定资产',
					content: '是否退出登录？',
					success: function(res) {
						if (res.confirm) {
							uni.showModal({
								title: '固定资产',
								content: '是否清理缓存',
								success: function(res2) {
									if (res2.confirm) {
										self.deleteBuildTable();
										uni.removeStorage({
											key:"盘点数据同步"
										});
										uni.removeStorage({
											key:"资产位置同步"
										});
										uni.removeStorage({
											key:"资产数据同步"
										});
										uni.navigateTo({
											url: '../login/login',
										});	
									}else{
										uni.navigateTo({
											url: '../login/login',
										});	
									}
								}
							});							
						}
					}
				});
			},
			deleteBuildTable() {
				//SQLite      
				openComDB('nfc', '_doc/nfcList.db', res => {
					console.log('打开数据库');
				});
			
				uni.setStorage({
					key: 'SaveStockDocumentCode',
					data: ''
				});
				//创建盘点单表；
				var sqlTable =
					'delete FROM MybuildTable'
				executeSQL('nfc', sqlTable, res => {
					console.log(res);
				})
			
				//创建盘点单明细表；
				var sqlTable2 =
					'delete FROM buildDetailTable'
				executeSQL('nfc', sqlTable2, res => {
					console.log(res);
				})
			
				//资产位置；
				var sqlTable3 =
					'delete FROM buildStore'
				executeSQL('nfc', sqlTable3, res => {
					console.log(res);
				})
			
				//创建资产表
				var sqlTable4 =
					'delete FROM buildAsset'
				executeSQL('nfc', sqlTable4, res => {
					console.log(res);
				})
				
			},
			confirmMoreBtns(theme){
				var _this = this;
				_this.auiDialog.title = '系统提示';
				_this.auiDialog.msg = '是否退出登录？';
				_this.auiDialog.items = [];
				_this.auiDialog.btns = [
					{name: '直接退出',color: "#6D8AF9"},
					{name: '清理缓存退出',color: "#6D8AF9"}, 
					{name: "取消", color: "#909090"}
				];
				_this.auiDialog.theme = theme;
				_this.$refs.dialog.show();
			},//dialog弹窗底部按钮回调
			dialogCallback(e){
				var _this = this;
				self=this;
				console.log(e);			
				if(_this.$refs.dialog.getVal().length > 0)
				{ //prompt输入框——点击确定时弹出输入内容
					_this.auiDialog.title = '系统提示';
					_this.$refs.dialog.getVal().forEach(function(item, index){
						_this.auiDialog.msg += '<div style="display: flex;">' + item.label + '：' + item.value + '</div>';
					});
					_this.auiDialog.btns = [{name: '确定', color: '#6D8AF9'}];
					_this.auiDialog.items = [];
					_this.auiDialog.theme = 1;
					_this.$refs.dialog.show();
				}
				if(e.msg=="直接退出"){
					uni.navigateTo({
						url: '../login/login',
					});	
				}else if(e.msg=="清理缓存退出"){
					self.deleteBuildTable();
					uni.removeStorage({
						key:"盘点数据同步"
					});
					uni.removeStorage({
						key:"资产位置同步"
					});
					uni.removeStorage({
						key:"资产数据同步"
					});
					uni.navigateTo({
						url: '../login/login',
					});	
				}
				
			},
			openWin(url, opts){
				aui.openWin(url, opts)
			},
			closeWin(){
				aui.closeWin();
			}
		}
	}
</script>

<style>
	.content {
		background-color: #edf1f4;
	}

	.content .topcomtent {
		background-color: #6D8AF9;
		height: 380rpx;
	}

	.content_Gaik {
		margin: 20rpx 20rpx;
		margin-top: 15rpx;
		margin-bottom: 0rpx;
		height: 385rpx;
		font-size: 25rpx;
		border-radius: 10px;
		border: 0px red solid;
	}

	.content_head {
		height: 140rpx;
		line-height: 140rpx;
		margin-top: 50rpx;
		margin-left: 50rpx;
	}

	.content_head_zcnum {
		line-height: 80rpx;
		height: 80rpx;
		text-align: center;
		margin-top: -20rpx;
		color: #6D8AF9;
	}

	.item-icon {
		width: 250rpx;
		height: 250rpx;

		border-radius: 30px;
	}

	.item-icon-manager {
		width: 80upx;
		height: 80upx;
	}
</style>
